<template>
  <div class="report-form-content">
    <el-form class="my-form"
             ref="objForm"
             :model="obj"
             :rules="rules"
             label-position="right"
             label-width="auto"
             label-suffix="："
             :disabled="oper === 'view' || oper === 'supplement'">
      <div class="tabs-form-head">
        <span>合同纠纷</span>
        <div class="">
          <el-button type="primary" plain @click="returnBtn">取消</el-button>
          <el-button type="primary" @click="doSubmit">登记纠纷</el-button>
        </div>
      </div>
      <el-divider border-style="dashed" />
      <el-row :gutter="20">
        <el-col :sm="24" :lg="24" style="padding-left: 20px">
          <el-card class="update-log">
            <div class="report-form-list-content-1">
              <el-form-item label="合同纠纷原因" prop="disputeReason">
                <el-input v-model="obj.disputeReason" :autosize="{ minRows: 2, maxRows: 5}" type="textarea" class="textarea-1" />
              </el-form-item>
            </div>
            <div class="report-form-list-content-1">
              <el-form-item label="对方意见" prop="disputeSecond">
                <el-input v-model="obj.disputeSecond" :autosize="{ minRows: 2, maxRows: 5}" type="textarea" class="textarea-1" />
              </el-form-item>
            </div>
            <div class="report-form-list-content">
              <el-form-item label="对方意见记录时间" prop="disputeSecondTime">
                <el-date-picker v-model="obj.disputeSecondTime" type="date" placeholder="选择日期" value-format="YYYY-MM-DD" />
              </el-form-item>
            </div>
            <div class="report-form-list-content-1">
              <el-form-item label="我方意见" prop="disputeFirst">
                <el-input v-model="obj.disputeFirst" :autosize="{ minRows: 2, maxRows: 5}" type="textarea" class="textarea-1" />
              </el-form-item>
            </div>
            <div class="report-form-list-content">
              <el-form-item label="我方意见记录时间" prop="disputeFirstTime">
                <el-date-picker v-model="obj.disputeFirstTime" type="date" placeholder="选择日期" value-format="YYYY-MM-DD" />
              </el-form-item>
            </div>
            <div class="report-form-list-content-1">
              <el-form-item label="处理结果" prop="disputeResult">
                <el-input v-model="obj.disputeResult" :autosize="{ minRows: 2, maxRows: 5}" type="textarea" class="textarea-1" />
              </el-form-item>
            </div>
          </el-card>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>
<script setup>
import {ref, getCurrentInstance} from 'vue'
import {doPost} from "@/config/http";
import {svc, notifySuccess, alertErrorMsg} from "@/config/common";
import { useRoute, useRouter } from 'vue-router'

const router = useRouter()
const route = useRoute()

const { proxy: ctx } = getCurrentInstance();

let objForm = ref(null)
const oper = ref(route.query.oper)

let obj = ref({
  contractInitialId: route.query.id, // 合同ID
  batch: null, // 批次号
  disputeReason: null, // 合同纠纷原因
  disputeSecond: null, // 对方意见
  disputeSecondTime: null, // 对方意见记录时间
  disputeFirst: null, // 我方意见
  disputeFirstTime: null, // 我方意见记录时间
  disputeResult: null, // 处理结果
  id: null,
  createBy: null,
  createTime: null,
  updateBy: null,
  updateTime: null,
  deleted: null,
  version: null,
})

let objList = ref([])

const rules = {}

const doSubmit = async () => {
  let v = await objForm.value.validate().catch((err)=>{return err})
  if (v !== true) {
    alertErrorMsg('表单验证不通过，请检查数据。')
    return
  }
  let o = {}
  o.oper = 'add'
  o.approveId = null
  o.approveNodes = []
  o.items = [obj.value]
  doPost(svc, `/customContractInitial/disputeContractInitial/${route.query.id}`, o, true).then(() => {
    notifySuccess('操作成功')
    returnBtn()
  })
}

const returnBtn = () => {
  switch (route.query.kind) {
    case '1':
      ctx.goTargetByName('contractInitial', {});
      break;
    case '2':
      ctx.goTargetByName('contractMain', {})
      break;
  }
}
</script>
<style scoped>
.report-form-content {
  padding: 20px;
}
.update-log {
  width: 100%;
  margin: 30px 0;
}
.report-list span:nth-child(1) {
  display: inline-block;
  width: 120px;
  text-align: right;
}
.tabs-form-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.tabs-form-head span {
  font-size: 18px;
  color: #303133;
  font-weight: bold;
}
</style>
